package com.jic.finance.impl;

import java.lang.Long;
import java.util.List;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.finance.entity.PaymentMethod;
import com.jic.finance.mapper.PaymentMethodMapper;
import com.jic.finance.request.manager.PaymentMethodRequest;
import com.jic.finance.service.PaymentMethodService;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 支付方式表
 * @author : 
 * @email : 
 * @since : 2020-02-28 03:00:56
 * @version : v1.0.0
 */
@Service
public class PaymentMethodServiceImpl implements PaymentMethodService{

    @Autowired
    private PaymentMethodMapper paymentMethodMapper;

    @Override
    public long insert(PaymentMethodRequest paymentMethodRequest) {
        PaymentMethod method = new PaymentMethod();
        BeanUtils.copyProperties(paymentMethodRequest,method);
        return paymentMethodMapper.insert(method);
    }

    @Override
    public long delete(Long id) {
        return paymentMethodMapper.delete(id);
    }

    @Override
    public long update(PaymentMethodRequest paymentMethodRequest) {
        return paymentMethodMapper.update(paymentMethodRequest);
    }

    @Override
    public PaymentMethod queryByPrimaryKey(Long id){
        return paymentMethodMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<PaymentMethod> query(PaymentMethod paymentMethod){
        return paymentMethodMapper.query(paymentMethod);
    }

    @Override
    public PageResult<PaymentMethod> queryPage(PaymentMethodRequest paymentMethodRequest, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<PaymentMethod> list = paymentMethodMapper.queryPage(startIndex, pageQuery.getLimit(), paymentMethodRequest);
        long count = paymentMethodMapper.queryPageCount(paymentMethodRequest);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}